package com.agenda.controller;

import com.agenda.concorrencia.Semaforo;
import com.agenda.model.Usuario;

public class EmoticonController {

	private static EmoticonController INSTANCE;

	public static EmoticonController getINSTANCE() {
		if (INSTANCE == null)
			INSTANCE = new EmoticonController();

		return INSTANCE;
	}

	private Semaforo semaforo;
	private Boolean sendoUsado = new Boolean(false);

	private EmoticonController() {
		semaforo = new Semaforo();
	}

	public Boolean reservarEmoticom(Usuario usuario) {

		Boolean reservou = new Boolean(false);
		semaforo.DOWN();

		if (!sendoUsado) {
			sendoUsado = Boolean.TRUE;
			reservou = Boolean.TRUE;
		}

		semaforo.UP();

		return reservou;
	}

	public void liberarEmoticom() {
		semaforo.DOWN();

		sendoUsado = Boolean.FALSE;

		semaforo.UP();
	}

}
